import config from '@/config'

// 上传图片
export function uploadImage(filePath) {
	return new Promise((resolve, reject) => {
		uni.uploadFile({
			url: config.apiBaseUrl + '/api/upload/image',
			filePath,
			name: 'image',
			header: {
				'Authorization': uni.getStorageSync('token')
			},
			success: (res) => {
				const data = JSON.parse(res.data)
				console.log({data});
				
				if (data.status === 200) {
					resolve(data.data.url)
				} else {
					reject(new Error(data.message || '上传失败'))
				}
			},
			fail: (err) => {
				reject(err)
			}
		})
	})
}

// 提交反馈
export function submitFeedback(data) {
	return new Promise((resolve, reject) => {
		uni.request({
			url: config.apiBaseUrl + '/api/feedback/create',
			method: 'POST',
			header: {
				'Authorization': uni.getStorageSync('token')
			},
			data,
			success: (res) => {
				if (res.data.code === 200) {
					resolve(res.data)
				} else {
					reject(new Error(res.data.message || '提交失败'))
				}
			},
			fail: (err) => {
				reject(err)
			}
		})
	})
} 